package cn.itcast.web.servlet;

import cn.itcast.domain.Req;
import cn.itcast.service.ReqService;
import cn.itcast.service.impl.ReqServiceImpl;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException;
import java.util.List;

@WebServlet("/reqServlet")
public class ReqServlet extends HttpServlet {
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        //1调用service方法
        ReqService service=new ReqServiceImpl();
        List<Req> reqs=service.findAll();
        //2将list存入request域中
        request.setAttribute("reqs",reqs);
        //3转发到Reqlist.jsp中
        request.getRequestDispatcher("/Reqlist.jsp").forward(request,response);

    }

    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        this.doPost(request, response);
    }
}
